#include <stdio.h>
#include <string.h>

#define BUF_SIZE 4096

int
main(int argc, char **argv)
{
	 FILE *ffiles = fopen(argv[1], "rb");
	 FILE *fnames = fopen(argv[2], "rb");
	 FILE *fout   = fopen(argv[3], "wb");
	 
	 char buf[BUF_SIZE];
	 int cur_idx = 0;
	 
	 while (1)
	 {
		  int  len;
		  char filename[80];
		  char name[80];
		  if (fscanf(ffiles, "%s", filename) == -1) break;
		  if (fscanf(fnames, "%s", name) == -1) break;
		  if ((len = strlen(name)) == 0) break;

		  name[len] = 0;
		  fputc(0, fout);
		  fwrite(&len, 4, 1, fout);
		  fwrite(name, 1, len + 1, fout);
		  
		  FILE *fr = fopen(filename, "rb");
		  fseek(fr, 0, SEEK_END);
		  int size = ftell(fr);
		  fseek(fr, 0, SEEK_SET);
		  
		  fwrite(&size, 4, 1, fout);

		  int i = 0;
		  for (i = 0; i != size / BUF_SIZE; ++ i)
		  {
			   fread(buf, BUF_SIZE, 1, fr);
			   fwrite(buf, BUF_SIZE, 1, fout);
		  }
		  
		  if (size % BUF_SIZE != 0)
		  {
			   fread(buf, size % BUF_SIZE, 1, fr);
			   fwrite(buf, size % BUF_SIZE, 1, fout);
		  }
		  
		  fclose(fr);
	 }

	 fputc(1, fout);
	 fclose(ffiles); fclose(fnames); fclose(fout);
     return 0;	  
}
